﻿<#macro ckeditor config="default" id="editor1" name="editor1" class="" value="" width="860" height="360"> 
  <textarea id="${id}" name="${name}" class="${class}">${value}</textarea>
    <#if config == "full">
    <input type="hidden" id="_imgs_record" name="_imgs_record" value=""/>
    <input type="hidden" id="_imgs_before_update" name="_imgs_before_update" value="<#if _imgs_before_update_val!=null>${_imgs_before_update_val}</#if>"/>
    <input type="hidden" id="_imgs_for_bind_require" name="_imgs_for_bind_require" value="false"/>
    </#if>
    <script type="text/javascript">
		//<![CDATA[
            var _config = '${config}';
            if(_config == "simple") {
               CKEDITOR.replace('${id}', {height:${height}, width:${width}, resize_enabled:false, customConfig: '${base}/js/ckeditor/config_simple.js',filebrowserImageUploadUrl : '${base}/admin/common/ckeditor.do?uploadRuleId=${uploadRuleId!""}&uploadType=${uploadType!""}' });  
            }else{
               CKEDITOR.replace('${id}', {height:${height}, width:${width},filebrowserImageUploadUrl : '${base}/admin/common/ckeditor.do?uploadRuleId=${uploadRuleId!""}&uploadType=${uploadType!""}'}); 
            }
			CKEDITOR.on('dialogDefinition', function(ev){
	     	  var dialogName = ev.data.name;
		      var dialogDefinition = ev.data.definition;
				if (dialogName == 'image'){		
					dialogDefinition.removeContents('advanced');
					if(_config != "full") {
					   dialogDefinition.removeContents('Upload');
					}
				}
				if (dialogName == 'Link'){	
					dialogDefinition.removeContents('advanced');
				}
            });
           CKEDITOR.logImgs = function() {
              var _body = document.getElementsByTagName("body")[0];
              var _xdiv_ = document.createElement("div");
              _xdiv_.style.display = "none";
              _xdiv_.innerHTML = CKEDITOR.instances.${id}.getData();
              var _imgs_ = _xdiv_.getElementsByTagName("img");
              var _o = document.getElementById("_imgs_record");
              var _src = "";
              for(var n = 0; n < _imgs_.length; n++) {
                 _src = _imgs_[n].src;
                 if(_src.indexOf("${base}") != -1){
                    _src = _src.substring("${base}".length);
                    _o.value += _src;
                    if(n != _imgs_.length -1) _o.value += ",";
                 }
			  }
			  document.getElementById("_imgs_for_bind_require").value = true;
           }
		//]]>
	</script>
</#macro>
